package com.itbaizhan.escase.controller;

import com.itbaizhan.escase.document.News;
import com.itbaizhan.escase.service.NewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//http://localhost:8080/news.html
@RestController
public class NewController {
    @Autowired
    private NewService newService;
    //这里一般是get请求，因为是查询为主
    //访问路径：localhost:8080/autoSuggest
    //使用jqueryUI工具，参数直接从前端传进来，jqueryUI参数名是term,所以这里一般也写term
    @GetMapping("/autoSuggest")
    public List<String> autoSuggest(String term){
        return newService.autoSuggest(term);
    }

    @GetMapping("/highLightSearch")
    public List<News> highLightSearch(String term){
        if(StringUtils.isEmpty(term)){
            int i = 1/0;
        }
        return newService.highLightSearch(term);
    }
}
